<template>
	<view class="content">
		<!-- 导航组件 -->
		<pyh-nv :config="config"></pyh-nv>
		
		<!-- 滚动列表 -->
		<scroll-view class="listBox" scroll-y="true" v-if="content.length>0" @scrolltolower="getMore">
			<view class="listItem" v-for="(item, index) in content" :key="index">
				<!-- 左侧用户信息 -->
				<view class="left">
					<image :src="item.userData.avatar" class="avatar"></image>
					<text class="nickName">{{ item.userData.nickname }}</text>
				</view>
				<!-- 右侧操作按钮 -->
				<view class="right">
					<view class="tongguo" @click="handle(item.id, 1, item.community_id, index)">
						通过
					</view>
					<view class="jujue" @click="handle(item.id, 2, item.community_id, index)">
						拒绝
					</view>
				</view>
			</view>
		</scroll-view>
		<view class="noBox" v-else>
			<text class="noText">暂时还没有人申请入群</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseurl: this.$baseurl,
				// 导航配置
				config: {
					title: '社群成员审核',
					bgColor: 'transparent',
					color: '#000',
				},
				// 列表数据
				content: [],
				// 分页参数
				page: 1,
				// 是否有更多数据
				haveMore: true,
			}
		},
		
		onLoad() {
			// 初始加载数据
			this.getData()
		},
		
		methods: {
			// 加载更多数据
			getMore() {
				if (this.haveMore) {
					this.page++;
					this.getData();
				} else {
					this.$toast({
						title: '暂无更多数据'
					})
				}
			},
			
			// 获取列表数据
			getData() {
				this.$request.get(`CommunityUser/audit_list?page=${this.page}`).then(res => {
					// 追加数据
					this.content.push(...res.data.data);
					// 判断是否还有更多数据
					if (res.data.data.length === 0) {
						this.haveMore = false;
					}
				})
			},
			
			// 处理审核操作
			handle(id, status, community_id, index) {
				// 提示内容
				let content = status === 1 ? "是否通过申请" : "是否拒绝申请";
				
				// 显示确认弹窗
				uni.showModal({
					title: '提示',
					content: content,
					success: (res) => {
						if (res.confirm) {
							// 提交审核请求
							this.$request.post(`CommunityUser/audit_apply`, {
								id: id,
								status: status,
								community_id: community_id
							}).then(res => {
								// 显示操作结果
								this.$u.toast(res.data.msg);
								// 拒绝操作：从列表中删除当前项
								if (status === 1 || status === 2) {
									this.content.splice(index, 1);
								} else {
									// 通过操作：重新获取列表（保持原逻辑）
									this.getData();
								}
							})
						}
					}
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.noBox {
		width: 100%;
		height: 100%;
	}
	.noText {
		display: block;
		width: 100%;
		text-align: center;
		font-size: 28rpx;
		color: #8E8E8E;
		margin-top: 600rpx;
	}
	.listBox {
		width: 670rpx;
		height: 80vh;
		margin-left: 40rpx;
		margin-top: 40rpx;
	}

	.listItem {
		position: relative;
		width: 100%;
		height: 100rpx;
		margin-bottom: 50rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.left, .right {
			display: flex;
			align-items: center;
		}

		.avatar {
			width: 100rpx;
			height: 100rpx;
			border-radius: 50%;
		}

		.nickName {
			margin-left: 45rpx;
			width: 275rpx;
			font-size: 32rpx;
			font-weight: 700;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}

		.tongguo {
			width: 118rpx;
			height: 56rpx;
			border-radius: 28rpx;
			margin-right: 15rpx;
			background-color: #4E97AD;
			font-size: 22rpx;
			color: #fff;
			text-align: center;
			line-height: 56rpx;
		}

		.jujue {
			width: 118rpx;
			height: 56rpx;
			border-radius: 28rpx;
			background-color: #D95945;
			font-size: 22rpx;
			color: #fff;
			text-align: center;
			line-height: 56rpx;
		}

		.yijujue {
			width: 118rpx;
			height: 56rpx;
			border-radius: 28rpx;
			background-color: #B8B8B8;
			font-size: 22rpx;
			color: #fff;
			text-align: center;
			line-height: 56rpx;
		}

		.yitongguo {
			width: 118rpx;
			height: 56rpx;
			border-radius: 28rpx;
			background-color: #A7CEDB;
			font-size: 22rpx;
			color: #fff;
			text-align: center;
			line-height: 56rpx;
		}
	}

	.content {
		position: fixed;
		width: 100%;
		height: 100vh;
		background-color: #fff;
		overflow-y: scroll;
		background: url("https://miantou.guguan.net/img/common/bg.png");
		background-size: 100% auto;
	}

	/deep/ page {
		width: 100% !important;
		height: 100vh !important;
		padding-bottom: 0 !important;
	}
</style>
